<?php
include("_session.php");
unset($_SESSION['ORDER_DETAIL']);
if(count($_POST)>0)
{
	$dist = str_pad($_POST["DIST"],4,0,STR_PAD_LEFT);
	$mslno = str_pad($_POST["MSLNO"],5,0,STR_PAD_LEFT);
	$chkdgt = $_POST["CHKDGT"];
	$ordcamp = $_POST["ORDCAMP"];
	$memberno = mergeMsl($dist, $mslno, $chkdgt);
	/*
			INNER JOIN order_detail od ON 
				(	oh.ORDER_NO = od.ORDER_NO AND
					oh.ORDCAMP = od.ORDCAMPH AND
					oh.DIST = od.DIST AND
					oh.MSLNO = od.MSLNO AND
					oh.CHKDGT = od.CHKDGT	)
	*/	
	$sql = "SELECT * FROM order_header oh 
			WHERE 
			oh.DIST ='".$dist."'  
		AND oh.MSLNO = ".$mslno." 
		AND oh.CHKDGT = ".$chkdgt." 
		AND oh.ORDCAMP = ".$ordcamp." 
		AND oh.DELFLAG = 'N'
		AND oh.DWNFLAG = 'N'";
		//echo $sql;
	$raw = mysql_query($sql, $conn);
	$row = mysql_fetch_array($raw, MYSQL_ASSOC);
	if (is_array($row))
	{
		$order_no = $row["ORDER_NO"];
		header("Location:editorder.php?dist=$dist&mslno=$mslno&chkdgt=$chkdgt&ordcamp=$ordcamp&order_no=$order_no");
	}
	else
	{
		header("Location:neworder.php?dist=$dist&mslno=$mslno&chkdgt=$chkdgt&ordcamp=$ordcamp");	
	}		
}


?>